<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<link rel="stylesheet" type="text/css" href="<c:url value="/css/uploadify.css" />">
	<script type="text/javascript" src="<c:url value="/scripts/jquery.uploadify.min.js" />"></script>
	
	<style>
		.input-text {width: 460px;}
		textarea {width: 460px;height: 150px;}
	</style>
</head>

<body>
	<div class="wrapper">
		<form action="<c:url value="/bug/saveBug.do" />" onsubmit="initForm();" method="post">
		
		<div id="btnDiv">
			<c:if test="${param.op == null || param.op == ''}">
				<input type="submit" class="btn" value="保存" onclick="setType(0);" />
				<input type="submit" class="btn" value="提交" onclick="setType(1);" />
				<a href="bug.jsp" class="btn">返回</a>
			</c:if>
			
			<c:if test="${param.op == 'edit'}">
				<input type="submit" class="btn" value="保存" onclick="setType(0);" />
				<a href="<c:url value="/bug/openBug.do?bugId=${param.bugId}" />" class="btn">返回</a>
			</c:if>
		</div>
		
		<table class="edit-table">
			<tr>
				<td class="left-td" width="80px">缺陷名称</td>
				<td><input name="name" type="text" class="input-text input-require" value="${bug.name}" /></td>
			</tr>
			<tr>
				<td class="left-td">所属项目</td>
				<td><input id="project" type="text" class="input-text input-require" ondblclick="showProjects($(this));" onkeydown="return false;" val="${bug.projectId}" value="${bug.projectName}" /><i onclick="$(this).prev().dblclick();" class="icon-search input-icon"></i></td>
			</tr>
			<tr>
				<td class="left-td">审核人</td>
				<td><input id="auditor" type="text" class="input-text input-require" ondblclick="showUsers($(this));" onkeydown="return false;" val="${bug.ownerId}" value="${bug.owner}" /><i onclick="$(this).prev().dblclick();" class="icon-search input-icon"></i></td>
			</tr>
			<tr>
				<td class="left-td">缺陷描述</td>
				<td><textarea name="intro">${bug.intro}</textarea></td>
			</tr>
			<tr>
				<td class="left-td">重现步骤</td>
				<td><textarea name="reappear">${bug.reappear}</textarea></td>
			</tr>
			<tr>
				<td class="left-td" colspan="2">附件</td>
			</tr>
			<tr>
				<td class="left-td" colspan="2"><input id="file_upload" type="file" /></td>
			</tr>
		</table>
		
		<input type="hidden" name="id" value="${param.bugId}" />
		<input type="hidden" id="_type" name="type" />
		<input type="hidden" id="_projectId" name="projectId" />
		<input type="hidden" id="_auditorId" name="auditorId" />
		<input type="hidden" id="_attachIds" name="attachIds" />
		
		</form>
	</div>

	<jsp:include page="/pages/common/projectSelect.jsp"></jsp:include>
	<jsp:include page="/pages/common/userSelect.jsp"></jsp:include>
	
	<script>
		var type, attachIds = [];
		
		$("#file_upload").uploadify({
			buttonText: "上传",
			removeCompleted: false,
			swf: parent.basePath + "/css/uploadify.swf",
			uploader : parent.basePath + "/upload.action",
			onQueueComplete: function() {
				parent.autoHeight();
			},
			onUploadSuccess: function(file, data, response) {
				attachIds.push(data);
			}
		});
		
		function setType(t) {
			type = t;
		}
	
		function initForm() {
			var pVal = $("#project").attr("val"), aVal = $("#auditor").attr("val");
			$("#_projectId").val(pVal ? pVal : "");
			$("#_auditorId").val(aVal ? aVal : "");
			
			$("#_type").val(type);
			$("#_attachIds").val(attachIds.join(","));
			
			return false;
		}
	</script>
</body>
</html>
